<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns="http://www.w3.org/1999/xhtml" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xi="http://www.w3.org/2001/XInclude"
	xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:saxon="http://saxon.sf.net/" xmlns:widget="http://orbeon.org/oxf/xml/widget" xmlns:numishare="http://code.google.com/p/numishare/">
	<xhtml:head>
		<title>Numishare: Edit Numishare Settings</title>
		<!-- Core + Skin CSS -->
		<xhtml:link rel="stylesheet" type="text/css" href="/apps/numishare/css/jquery-ui-1.8.10.custom.css"/>
		<xhtml:link rel="stylesheet" href="/apps/numishare/css/reset-fonts-grids.css"/>
		<xhtml:link rel="stylesheet" href="/apps/numishare/css/base-min.css"/>
		<xhtml:link rel="stylesheet" href="/apps/numishare/css/fonts-min.css"/>

		<!-- numishare styling -->
		<xhtml:link rel="stylesheet" href="/apps/numishare/css/xforms.css"/>

		<xhtml:script type="text/javascript" src="/apps/numishare/javascript/jquery-1.6.1.min.js"/>
		<xhtml:script type="text/javascript" src="/apps/numishare/javascript/numishare-menu.js"/>
		<xforms:model>
			<!-- exist URL is stored in an XML file -->
			<xforms:instance id="exist-url">
				<xi:include href="exist-url.xml"/>
			</xforms:instance>

			<!-- collections/authentication instances -->
			<xforms:instance id="collections-list">
				<collections xmlns="">
					<collection roll="admin" name="numishare"/>
				</collections>
			</xforms:instance>

			<xforms:instance id="config">
				<config xmlns=""/>
			</xforms:instance>

			<xforms:instance id="status">
				<status/>
			</xforms:instance>

			<xforms:instance id="flickr-response">
				<rsp xmlns=""/>
			</xforms:instance>

			<xforms:instance id="control-instance">
				<control xmlns="">
					<api-key-accepted/>
					<save-trigger/>
					<collection-name/>
				</control>
			</xforms:instance>

			<xforms:instance id="dump">
				<dump/>
			</xforms:instance>

			<xforms:instance id="temp">
				<temp/>
			</xforms:instance>

			<!--<xforms:instance id="serialized-footer">
				<div xmlns=""/>
			</xforms:instance>-->

			<xforms:action ev:event="xforms-model-construct-done">
				<xforms:insert context="instance('control-instance')" nodeset="collection-name" position="after"
					origin="xxforms:call-xpl('oxf:/apps/numishare/xpl/get-authentication.xpl', 'dump', instance('dump'), 'data')"/>
				<xforms:send submission="load-collections"/>
			</xforms:action>

			<!--<xforms:action ev:event="xforms-ready">
				<xforms:setvalue ref="instance('serialized-footer')"
					value="saxon:serialize(instance('config')/footer, 'html')"/>
			</xforms:action>-->

			<xforms:instance id="languageselect-template" src="/apps/numishare/instances/languages.xml"/>
			
			<xforms:instance id="licenseselect-template">
				<licenses xmlns="">
					<license href="http://opendatacommons.org/licenses/odbl/">Open Data Commons Open Database License (ODbL)</license>
					<license href="http://opendatacommons.org/licenses/by/">Open Data Commons Attribution License</license>
					<license href="http://opendatacommons.org/licenses/pddl/">Open Data Commons Public Domain Dedication and License (PDDL)</license>
				</licenses>
			</xforms:instance>

			<xforms:bind nodeset="instance('config')">
				<xforms:bind nodeset="title" required="true()"/>
				<xforms:bind nodeset="description" required="true()"/>
				<!--<xforms:bind nodeset="banner_text" required="true()"/>-->
				<xforms:bind nodeset="url" required="true()"/>
				<xforms:bind nodeset="solr_published" required="true()"/>
				<xforms:bind nodeset="features_enabled" type="xs:boolean"/>
				<xforms:bind nodeset="pelagios_enabled" type="xs:boolean"/>
				<xforms:bind nodeset="ctype_enabled" type="xs:boolean"/>
				<xforms:bind nodeset="template">
					<!-- about the electronic record -->
					<xforms:bind nodeset="publisher" required="true()"/>
					<xforms:bind nodeset="copyrightHolder" required="true()"/>
					<xforms:bind nodeset="createdBy"/>
					<xforms:bind nodeset="project"/>
					<xforms:bind nodeset="language">
						<xforms:bind constraint="string-length(@langcode) &gt; 0"/>
					</xforms:bind>
					<!-- about the physical item -->
					<xforms:bind nodeset="repository"/>
					<xforms:bind nodeset="owner"/>
					<xforms:bind nodeset="collection"/>
				</xforms:bind>
				<xforms:bind nodeset="images">
					<xforms:bind nodeset="thumbnail" required="true()" type="xs:integer"/>
					<xforms:bind nodeset="reference" required="true()" type="xs:integer"/>
				</xforms:bind>
			</xforms:bind>

			<xforms:bind nodeset="instance('control-instance')/save-trigger" readonly="../api-key-accepted = 'false'"/>

			<xforms:submission id="load-collections" serialization="none" method="get" action="{instance('exist-url')}collections-list.xml" replace="instance" instance="collections-list"
				xxforms:username="admin" xxforms:password="">
				<!-- if the config loads successfully, set the collection names based on authentication -->
				<xforms:action ev:event="xforms-submit-done">
					<!-- set default if security is false -->
					<xforms:action if="not(string(instance('control-instance')/request-security/role))">
						<xforms:setvalue ref="instance('control-instance')/collection-name">numishare</xforms:setvalue>
					</xforms:action>
					<!-- if there is a security role, set the collection-name value if it is in the list, otherwise set new collection name -->
					<xforms:action if="string(instance('control-instance')/request-security/role)">
						<xforms:action if="string(instance('collections-list')/collection[@role=instance('control-instance')/request-security/role]/@name)">
							<xforms:setvalue ref="instance('control-instance')/collection-name"
								value="instance('collections-list')/collection[@role=instance('control-instance')/request-security/role]/@name"/>
						</xforms:action>
					</xforms:action>
					<xforms:send submission="load-config"/>
				</xforms:action>
				<!-- if the config has not been created (given that the URL in exist-url.xml is correct), create it -->
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to load Numishare collections list.</xforms:message>
			</xforms:submission>

			<!-- Load File -->
			<xforms:submission id="load-config" serialization="none" method="get" action="{instance('exist-url')}{instance('control-instance')/collection-name}/config.xml" xxforms:username="admin"
				xxforms:password="" replace="instance" instance="config">
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to load Numishare configuration file</xforms:message>
			</xforms:submission>

			<!-- Save File -->
			<xforms:submission id="save-config" ref="instance('config')" xxforms:username="admin" xxforms:password=""
				action="{instance('exist-url')}{instance('control-instance')/collection-name}/config.xml" method="put" replace="none">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Numishare configuration saved.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Error saving Numishare configuration file.</xforms:message>
			</xforms:submission>

			<!-- test for flickr echo -->
			<xforms:submission id="test-for-echo" serialization="none" method="get"
				action="http://api.flickr.com/services/rest/?method=flickr.test.echo&amp;api_key={instance('config')/flickr_api_key}" replace="instance" instance="flickr-response">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error querying flickr. Please check internet connection.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<!-- set readonly for save button if the api key is a string and failed -->
					<xforms:setvalue ref="instance('control-instance')/api-key-accepted" if="not(instance('flickr-response')/@stat = 'ok') and string-length(instance('config')/flickr_api_key) &gt; 0"
						value="'false'"/>

					<!-- activate button if the api key is okay or blank -->
					<xforms:setvalue ref="instance('control-instance')/api-key-accepted" if="instance('flickr-response')/@stat = 'ok'" value="'true'"/>
					<xforms:setvalue ref="instance('control-instance')/api-key-accepted" if="string-length(instance('config')/flickr_api_key) = 0" value="'true'"/>
				</xforms:action>

			</xforms:submission>
		</xforms:model>
		<xi:include href="oxf:/xbl/numishare/banner-upload/banner-upload.xbl" xi:omit-xml-base="true"/>
	</xhtml:head>

	<xhtml:body class="yui-skin-sam">
		<xhtml:div id="doc4" class="yui-t2 content ui-corner-all">
			<xxforms:variable name="display_path">../../</xxforms:variable>
			<xi:include href="header.xml"/>
			<div id="bd">
				<xhtml:div id="form">
					<xforms:group ref="instance('status')/text()">
						<div class="success">
							<xforms:output ref="instance('status')"/>
						</div>
					</xforms:group>
					<div class="submission">
						<xforms:trigger ref="instance('control-instance')/save-trigger" appearance="minimal">
							<xforms:label class="file_control"><img src="{$display_path}images/save.gif" alt="Save"/> Save</xforms:label>
							<xforms:send ev:event="DOMActivate" submission="save-config"/>
						</xforms:trigger>
					</div>
					<xhtml:h1>Edit Numishare Settings</xhtml:h1>
					<xhtml:p>Edit Numishare titles, URLs, and index text.</xhtml:p>
					<fr:tabview>
						<fr:tab id="settings">
							<fr:label>Settings</fr:label>
							<xforms:group ref="instance('config')">
								<div class="section">
									<h3>Titles and URLs</h3>
									<div>
										<xforms:input ref="title">
											<xforms:label>Title</xforms:label>
											<xforms:alert>Required</xforms:alert>
										</xforms:input>
										<p>The title of the site to be displayed in all web page titles and citations in PDF files.</p>
									</div>
									<div>
										<xforms:input ref="description">
											<xforms:label>Description</xforms:label>
											<xforms:alert>Required</xforms:alert>
										</xforms:input>
										<p>Enter a brief description of collection.  This is used for VOiD RDF for data sharing.</p>
									</div>
									<div>
										<xforms:input ref="banner_text">
											<xforms:label>Banner Text</xforms:label>
											<xforms:alert>Required</xforms:alert>
										</xforms:input>
										<p>Appears in the header banner. For more sophisticated control, edit header.xsl.</p>
									</div>
									<div>
										<xforms:input ref="url">
											<xforms:label>URL</xforms:label>
											<xforms:alert>Required</xforms:alert>
										</xforms:input>
										<p>Public URL of the site. Used in citations of and image references in PDF printouts. Changing this to an inactive URL will <b>not</b> break Numishare's core
											functionality, but web forms may be style-less since the Orbeon applications point to this URL for embedding css files.</p>
									</div>
									<div>
										<xforms:input ref="contact">
											<xforms:label>Contact Email</xforms:label>
										</xforms:input>
										<p>Optional contact email address for OpenSearch description.</p>
									</div>
									<div>
										<xforms:textarea ref="google_analytics/script">
											<xforms:label>Google Analytics</xforms:label>
										</xforms:textarea>
										<p>Copy and paste the javascript code between <b>&lt;script type="text/javascript"&gt;&lt;/script&gt;</b> provided by Google.</p>
									</div>
									<div>
										<xforms:select1 ref="collection_type">
											<xforms:label>Collection Type</xforms:label>
											<xforms:item>
												<xforms:label>object</xforms:label>
												<xforms:value>object</xforms:value>
											</xforms:item>
											<xforms:item>
												<xforms:label>hoard</xforms:label>
												<xforms:value>hoard</xforms:value>
											</xforms:item>
										</xforms:select1>										
										<p>Type of object collection: object (coins, non-coins, coin-type catalog) or hoard. This setting determines KML contents of maps page and the default operator
											when selecting facets.</p>
									</div>
									<div>
										<xforms:input ref="features_enabled">
											<xforms:label>Featured Item</xforms:label>
										</xforms:input>
										<p>If enabled (the default), the Featured Object function will be displayed in the index page. It does not function correctly in coin-type catalogs.</p>
									</div>
									<div>
										<xforms:input ref="pelagios_enabled">
											<xforms:label>Expose to Pelagios</xforms:label>
										</xforms:input>
										<p>If enabled, records linked to Pleiades-defined ancient places will be exposed at <xforms:output ref="concat(url, 'pelagios.rdf')"/> with the VOiD defined by <xforms:output ref="concat(url, 'pelagios.void.rdf')"/>.</p>
									</div>
									<div>
										<xforms:input ref="ctype_enabled">
											<xforms:label>Expose to Coin-Type Endpoint</xforms:label>
										</xforms:input>
										<p>If enabled, records linked to URI-defined coin types will be exposed at <xforms:output ref="concat(url, 'ctype.rdf')"/> with the VOiD defined by <xforms:output ref="concat(url, 'ctype.void.rdf')"/>.</p>
									</div>
									<xforms:group ref="banner_image">
										<numishare:banner-upload/>
									</xforms:group>
								</div>
								<div class="section">
									<h2>About this Numishare collection</h2>
									<xforms:group ref="template">
										<div class="subsection">
											<h3>Electronic Records</h3>
											<p>The following fields pertain to electronic records and will be populated automatically into each new object record. They can be changed on a per-document
												bases from within the object editing form. The publisher is the entity responsible for the web site which provides access to the electronic record. The
												copyright holder maintains the intellectual property (and may differ from the repository or physical custodian). The project field pertains to the
												project responsible for the creation of the record. CreatedBy denotes the individual responsible for entering metadata. The language refers to the
												language of the electronic record.</p>
											<p>Publisher, copyright holder, and language are required. Project and createdBy may be left blank.</p>
											<div>
												<xforms:input ref="publisher">
													<xforms:label>Publisher</xforms:label>
													<xforms:alert>Required</xforms:alert>
												</xforms:input>
											</div>
											<div>
												<xforms:input ref="copyrightHolder">
													<xforms:label>Copyright Holder</xforms:label>
													<xforms:alert>Required</xforms:alert>
												</xforms:input>
											</div>
											<div>
												<xforms:input ref="createdBy">
													<xforms:label>Created By</xforms:label>
													<xforms:alert>Required</xforms:alert>
												</xforms:input>
											</div>
											<div>
												<xforms:input ref="project">
													<xforms:label>Project</xforms:label>
												</xforms:input>
											</div>
											<div>
												<xforms:select1 ref="language">
													<xforms:label>Language</xforms:label>
													<xforms:item>
														<xforms:label>Select Language...</xforms:label>
														<xforms:value/>
													</xforms:item>
													<xforms:itemset nodeset="instance('languageselect-template')//language">
														<xforms:label ref="name"/>
														<xforms:value ref="name"/>
													</xforms:itemset>
													<xforms:alert>Required</xforms:alert>
													<xxforms:variable name="language" select="."/>
													<xforms:setvalue ref="@langcode" value="instance('languageselect-template')//language[name = $language]/code" ev:event="xforms-value-changed"/>
												</xforms:select1>
											</div>
											<div>
												<xforms:select1 ref="license">
													<xforms:label>License</xforms:label>
													<xforms:item>
														<xforms:label>Select License...</xforms:label>
														<xforms:value/>
													</xforms:item>
													<xforms:itemset nodeset="instance('licenseselect-template')//license">
														<xforms:label ref="."/>
														<xforms:value ref="href"/>
													</xforms:itemset>
												</xforms:select1>
											</div>
										</div>
										<div class="subsection">
											<h3>Physical Objects</h3>
											<p>The following fields pertain to attributes of the physical objects themselves. The collection is the public name of the physical collection. The owner
												field is an individual or corporate body which legally controls the object, and repository is the entity which serves as physical custodian. Objects on
												loan may have a different owner than repository.</p>
											<div>
												<xforms:input ref="collection">
													<xforms:label>Collection</xforms:label>
												</xforms:input>
											</div>
											<div>
												<xforms:input ref="owner">
													<xforms:label>Owner</xforms:label>
												</xforms:input>
											</div>
											<div>
												<xforms:input ref="repository">
													<xforms:label>Repository</xforms:label>
												</xforms:input>
											</div>
										</div>
									</xforms:group>
								</div>
								<div class="section">
									<h2>API Keys</h2>
									<h3>flickr</h3>
									<xforms:group ref=".[instance('flickr-response')/@stat='fail' and string-length(flickr_api_key) &gt; 0]">
										<div class="ui-widget">
											<div class="ui-state-error ui-corner-all">
												<p>
													<span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"/>
													<strong>Alert:</strong>
													<xforms:output ref="instance('flickr-response')/err/@msg"/>
												</p>
											</div>
										</div>
									</xforms:group>
									<div>
										<xforms:input ref="flickr_api_key" incremental="true">
											<xforms:label>Key</xforms:label>
											<xforms:send submission="test-for-echo" ev:event="xforms-value-changed"/>
										</xforms:input>
										<p>A <a href="http://www.flickr.com/services/api/misc.api_keys.html">flickr API key</a> is required in order to take advantage of flickr image linking in
											Numishare.</p>
									</div>
									<h3>geonames</h3>
									<div>
										<xforms:input ref="geonames_api_key" incremental="true">
											<xforms:label>Key</xforms:label>
										</xforms:input>
										<p>A <a href="http://www.geonames.org/export/web-services.html">geonames API key</a> is required in order to link geographical places to geonames ids.</p>
									</div>
								</div>
							</xforms:group>
						</fr:tab>
						<fr:tab id="index">
							<fr:label>Edit Index</fr:label>
							<xforms:group ref="instance('config')/pages/index">
								<xhtml:div>
									<xhtml:h3>Index Content</xhtml:h3>
									<xforms:textarea ref="." mediatype="text/html">
										<xforms:alert>Content Required.</xforms:alert>
									</xforms:textarea>
								</xhtml:div>
							</xforms:group>
						</fr:tab>
						<fr:tab id="footer">
							<fr:label>Edit Footer</fr:label>
							<xforms:group ref="instance('config')/footer">
								<xhtml:div>
									<xhtml:h3>Footer Content</xhtml:h3>
									<xforms:textarea ref="." mediatype="text/html"/>
								</xhtml:div>
							</xforms:group>
						</fr:tab>
						<fr:tab id="advanced">
							<fr:label>Advanced</fr:label>
							<xforms:group ref="instance('config')">
								<h2>Advanced Settings</h2>
								<xforms:group ref="images">
									<div class="section">
										<h3>Image Configuration</h3>
										<div>
											<xforms:input ref="thumbnail">
												<xforms:label>Thumbnail dimensions</xforms:label>
												<xforms:alert>Required, must be integer.</xforms:alert>
											</xforms:input>
											<p>Maximum height or width of thumbnails.</p>
										</div>
										<div>
											<xforms:input ref="reference">
												<xforms:label>Reference dimensions</xforms:label>
												<xforms:alert>Required, must be integer.</xforms:alert>
											</xforms:input>
											<p>Maximum height or width of reference sized images which display on item records and pop up in the search results.</p>
										</div>
										<div>
											<xforms:input ref="absolute_path">
												<xforms:label>Image Path</xforms:label>
												<xforms:alert>Required</xforms:alert>
											</xforms:input>
											<p>Absolute path to the cocoon on the server. This only needs to be changed if Numishare was installed to a different directory than the installation
												instructions recommend.</p>
										</div>
									</div>
								</xforms:group>
								<div class="section">
									<h3>Advanced Options</h3>
									<p>
										<b>Only change these options if Orbeon is run on a separate server.</b>
									</p>
									<p>Changing these options to an inactive URL could break public coin display and web form functionality. A backup file is located in the
										tomcat/webapps/cocoon/numishare/xml folder and must be uploaded to eXist in the event of site malfunction.</p>
									<div>
										<xforms:input ref="solr_published">
											<xforms:label>Solr URL</xforms:label>
											<xforms:alert>Required</xforms:alert>
										</xforms:input>
										<p>If Solr is run on a different server or core than the default, the Cocoon sitemap global variable must be edited manually in addition to this URL, which is
											referenced in Orbeon web forms.</p>
									</div>
								</div>
							</xforms:group>
						</fr:tab>
					</fr:tabview>
				</xhtml:div>
			</div>

			<!--<widget:xforms-instance-inspector id="orbeon-xforms-inspector" xmlns:widget="http://orbeon.org/oxf/xml/widget"/>-->

		</xhtml:div>
	</xhtml:body>
</xhtml:html>
